package com.adcc.zkdemo.web;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.*;

/**
 * Created by liup on 14-12-25.
 */
public class MenuArea extends Vlayout implements EventListener<Event> {

    public MenuArea()
    {
        this.createLayout();
    }

    private void createLayout()
    {
        this.setStyle("border:0;padding:8px");
        Button btn = new Button("Show Demo");
        btn.setWidth("100%");
        btn.setId("btnShowDemo");
        btn.addEventListener("onClick",this);
        Panel p = new Panel();
        p.appendChild(new Panelchildren());
        p.getPanelchildren().appendChild(btn);
        this.appendChild(p);
    }

    @Override
    public void onEvent(Event event) throws Exception {
        if (event.getName().equals(Events.ON_CLICK))
        {
            Component comp = event.getTarget();
            if(comp instanceof Button && comp.getId().equals("btnShowDemo"))
            {
                Page p =  Executions.getCurrent().getDesktop().getPage("Page_ViewPort_Main");
                Center mainContent = (Center)p.getFellowIfAny("ViewPort_Center");
                mainContent.getChildren().clear();
                mainContent.appendChild(new DataTable());
            }
        }

    }
}
